package code.c10;

import java.io.*;
import java.util.Arrays;

/**
 * @author thinkpad - 83start
 * @version v1.0
 * @create 2022/11/10 11:09
 * @package code.c10
 * @description 文件说明
 */

public class MyFileOutput {
    public static void main(String[] args) throws IOException {
        final String filePath = "./src/code/c10/file.txt";

        // 在 file 文件中 写入数据
        FileOutputStream fos = new FileOutputStream(filePath);
        fos.write("hello world".getBytes());
        fos.close();

        //1、得到数据文件
        File file = new File(filePath);
        //2、建立数据通道
        FileInputStream fileInputStream = new FileInputStream(file);
        byte[] buf = new byte[1024];
        int length = 0;
        //当文件读取到结尾时返回 -1,循环结束。
//        while ((length = fileInputStream.read(buf)) != -1) {
//            System.out.println(new String(buf, 0, length));
//        }

        while ((length = fileInputStream.read()) != -1) {
            System.out.print((char) length);
        }
        //关闭流
        fileInputStream.close();
    }
}
